package com.runshu.newsmartark.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Build;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.SuperscriptSpan;
import android.util.Base64;

import com.runshu.newsmartark.util.common.SharedPreferencesUtils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static android.content.Context.TELEPHONY_SERVICE;
import static com.runshu.newsmartark.common.ConstantUrl.Share_StockNum;

/**
 * <pre>
 *     Created by ppW
 *     e-mail : wangpanpan05@163.com
 *     time   : 2017/08/04
 *     desc   : 字符串操作工具类
 *     version: 1.0   初始化
 *     params:
 *  <pre>
 */

public class StringUtils {
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String YYYY_MM_DD_s = "yyyy/MM/dd";
    public static int scanFanwei(Context context){
      int fanwei =  Integer.parseInt(String.valueOf(SharedPreferencesUtils.get(context, Share_StockNum, "0")))/3;
      if(fanwei<20) fanwei=20;
      return fanwei;
    };
    public static String FormateMoney(String money) {

        DecimalFormat df1 = new DecimalFormat("###,###,###,##0.##");
        return df1.format(Double.parseDouble(money.equals("") ? "0" : money));
    }

    /**
     * @param longTime 毫秒值
     * @return 返回 HH:mm类型字符串
     */
    public static String getMonthHourChinese(long longTime) {
        SimpleDateFormat time = new SimpleDateFormat("MM月dd日");
        String result = time.format(new Date(longTime));
        return result;
    }


    public static SpannableStringBuilder getAtHeightLight(String text) {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
        Spanned htmlText = Html.fromHtml(String.format("<font color='%s'>" + text + "</font>", "#0000ff"));
        spannableStringBuilder.replace(0, text.length(), htmlText);
        return spannableStringBuilder;
    }

    public static long getLongMilionSeconds(String time) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = null;
        try {
            parse = f.parse(time);
        } catch (ParseException e) {
            return 0;
        }
        return parse.getTime();

    }


    /**
     * @param text  文本
     * @param color 修改字体颜色   顶置为#d22330   精华为#f4bf08
     * @return
     */
    public static SpannableStringBuilder setTextColor(String text, int color) {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(color), 0, 3,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableStringBuilder;
    }

    public static SpannableStringBuilder setTextColor(String text, int color, int start, int end) {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(color), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableStringBuilder;
    }


    /**
     * 得到中文路径的图片地址
     *
     * @param url
     * @return
     */
    public static String getChineseImageURL(String url) {
        String encode = null;
        try {
            encode = URLEncoder.encode(url, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String replace = encode.replace("%3A", ":")
                .replace("%2F", "/")
                .replace("%3D", "=")
                .replace("%2C", ",")
                .replace("%26", "&");
        return replace;
    }

    private static ThreadLocal<SimpleDateFormat> DateLocal = new ThreadLocal<SimpleDateFormat>();

    public static SimpleDateFormat getDateFormat() {
        if (null == DateLocal.get()) {
            DateLocal.set(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA));
        }
        return DateLocal.get();
    }

    public static SimpleDateFormat getDateFormat2() {
        if (null == DateLocal.get()) {
            DateLocal.set(new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA));
        }
        return DateLocal.get();
    }

    public static String getTodayOrYesterday(String str) {
        String strDes = "";
        Calendar pre = Calendar.getInstance();
        Date predate = new Date(System.currentTimeMillis());
        pre.setTime(predate);
        Calendar cal = Calendar.getInstance();
        Date date = null;
        try {
            date = getDateFormat().parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.setTime(date);
        if (cal.get(Calendar.YEAR) == (pre.get(Calendar.YEAR))) {
            int diffDay = cal.get(Calendar.DAY_OF_YEAR)
                    - pre.get(Calendar.DAY_OF_YEAR);
            if (diffDay == 0) {
                strDes = "今天";
            } else if (diffDay == -1) {
                strDes = "昨天";
            } else if (diffDay == 1) {
                strDes = "明天";
            } else {
                strDes = getYearMothDay(str);//直接显示时间
            }
        } else {
            strDes = getYearMothDay(str);//直接显示时间
        }
        return strDes + " " + getDateStringWeek(date);
    }

    public static String getTodayOrYesterday(long time) {
        String strDes = "";
        Calendar pre = Calendar.getInstance();
        Date predate = new Date(System.currentTimeMillis());
        pre.setTime(predate);
        Calendar cal = Calendar.getInstance();
        Date date = new Date(time);
        cal.setTime(date);
        if (cal.get(Calendar.YEAR) == (pre.get(Calendar.YEAR))) {
            int diffDay = cal.get(Calendar.DAY_OF_YEAR)
                    - pre.get(Calendar.DAY_OF_YEAR);
            if (diffDay == 0) {
                strDes = "今天";
            } else if (diffDay == -1) {
                strDes = "昨天";
            } else if (diffDay == 1) {
                strDes = "明天";
            } else {
                strDes = getYearMothDay(date);//直接显示时间
            }
        } else {
            strDes = getYearMothDay(date);//直接显示时间
        }
        return strDes + " " + getDateStringWeek(date);
    }

    public static String getTodayOrYesterday2(String str) {
        String strDes = "";
        Calendar pre = Calendar.getInstance();
        Date predate = new Date(System.currentTimeMillis());
        pre.setTime(predate);
        Calendar cal = Calendar.getInstance();
        Date date = null;
        try {
            date = getDateFormat2().parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.setTime(date);
        if (cal.get(Calendar.YEAR) == (pre.get(Calendar.YEAR))) {
            int diffDay = cal.get(Calendar.DAY_OF_YEAR)
                    - pre.get(Calendar.DAY_OF_YEAR);
            if (diffDay == 0) {
                strDes = "今天";
            } else if (diffDay == -1) {
                strDes = "昨天";
            } else if (diffDay == 1) {
                strDes = "明天";
            } else {
                strDes = getYearMothDay(str);//直接显示时间
            }
        } else {
            strDes = getYearMothDay(str);//直接显示时间
        }
        return strDes + " " + getDateStringWeek(date);
    }

    public static String getTodayOrYesterdayHomeMatch(String str) {
        String strDes = "";
        Calendar pre = Calendar.getInstance();
        Date predate = new Date(System.currentTimeMillis());
        pre.setTime(predate);
        Calendar cal = Calendar.getInstance();
        Date date = null;
        try {
            date = getDateFormat().parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.setTime(date);
        if (cal.get(Calendar.YEAR) == (pre.get(Calendar.YEAR))) {
            int diffDay = cal.get(Calendar.DAY_OF_YEAR)
                    - pre.get(Calendar.DAY_OF_YEAR);
            if (diffDay == 0) {
                strDes = "今天";
            } else if (diffDay == -1) {
                strDes = "昨天";
            } else if (diffDay == 1) {
                strDes = "明天";
            } else {
                strDes = getMMdd(str);//直接显示时间
            }
        } else {
            strDes = getMMdd(str);//直接显示时间
        }
        return strDes;
    }

    /**
     * 后台接口返回的时间，可以是yyyy-MM-dd HH:mm:ss 也可以是时间戳
     */
    public static String getUnificationTime(String str) {
        try {
            if (str.contains(":")) {
                return getTwoDaysDistance(str);
            } else {
                //时间戳
                return longStringToTwoDaysDistance(str);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }

    public static Date stringToDate(String time) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
        try {
            return dateFormat.parse(time);
        } catch (ParseException e) {
            return new Date();
        }
    }

    /**
     * 传入字符串事件 距离现在事件的间隔
     *
     * @param timeStr yyyy-MM-dd HH:mm:ss类型字符串
     * @return
     */
    public static String getTwoDaysDistance(String timeStr) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        try {
            Date date = dateFormat.parse(timeStr);
            Date dateToday = new Date();
            long timeToday = dateToday.getTime();
            long time = date.getTime();
            long timeLong = timeToday - time;
            if (timeLong < -10000) {
                return "未知时间";
            } else if (timeLong < 60 * 1000) {
                //一分钟之内
                return "刚刚";
            } else if (timeLong < 60 * 60 * 1000) {
                //一个小时之内
                timeLong = timeLong / 1000 / 60;
                return timeLong + "分钟前";
            } else {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                Calendar calendarToday = Calendar.getInstance();
                calendarToday.setTime(dateToday);
                //如果是今天
                if (calendar.get(Calendar.DAY_OF_YEAR) == calendarToday.get(Calendar.DAY_OF_YEAR)) {
                    return getMonthHourMinuteChinese(time);
                } else {
                    if (calendar.get(Calendar.YEAR) == calendarToday.get(Calendar.YEAR)) {
                        //如果是今年
                        return getMonthHourMinuteTime(time);
                    } else {
                        //如果不是今年
                        return longStringToStringChinese(time + "");
                    }
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * 传入字符串事件 距离现在事件的间隔
     *
     * @return
     */
    public static String getTwoDaysDistance(long time) {
        Date date = new Date(time);
        Date dateToday = new Date();
        long timeToday = dateToday.getTime();
        long timeLong = timeToday - time;
        if (timeLong < -10000) {
            return "未知时间";
        } else if (timeLong < 60 * 1000) {
            //一分钟之内
            return "刚刚";
        } else if (timeLong < 60 * 60 * 1000) {
            //一个小时之内
            timeLong = timeLong / 1000 / 60;
            return timeLong + "分钟前";
        } else {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            Calendar calendarToday = Calendar.getInstance();
            calendarToday.setTime(dateToday);
            //如果是今天
            if (calendar.get(Calendar.DAY_OF_YEAR) == calendarToday.get(Calendar.DAY_OF_YEAR)) {
                return getMonthHourMinuteChinese(time);
            } else {
                if (calendar.get(Calendar.YEAR) == calendarToday.get(Calendar.YEAR)) {
                    //如果是今年
                    return getMonthHourMinuteTime(time);
                } else {
                    //如果不是今年
                    return longStringToStringChinese(time + "");
                }
            }
        }
    }

    /**
     * date转化为字符串 YYYY_MM_DD
     *
     * @param data date对象
     * @return YYYY-MM-DD字符串
     */
    public static String getTimeStringYYYY_MM_DD(Date data) {
        return new SimpleDateFormat(YYYY_MM_DD).format(data);
    }

    /**
     * @param longTime 毫秒值
     * @return 返回 HH:mm类型字符串
     */
    public static String getHourMinuteTime(long longTime) {
        SimpleDateFormat time = new SimpleDateFormat("HH:mm");
        String result = time.format(new Date(longTime));
        return result;
    }

    public static String getHourMinuteTime(Date date) {
        SimpleDateFormat time = new SimpleDateFormat("HH:mm");
        String result = time.format(date);
        return result;
    }

    /**
     * @param
     * @return 返回 HH:mm类型字符串
     */
    public static String getYearMothDay(Date date) {
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd");
        return time.format(date);
    }


    /**
     * @param
     * @return 返回 HH:mm类型字符串
     */
    public static String getYearMothDay(String str) {
        SimpleDateFormat time = new SimpleDateFormat("yyyy/MM/dd");
        SimpleDateFormat time_mm = new SimpleDateFormat("yyyy-MM-dd");
        String result = "";
        try {
            Date parse = time_mm.parse(str);
            result = time.format(parse);
        } catch (ParseException e) {
            return "";
        }

        return result;
    }

    /**
     * @param
     * @return 返回 HH:mm类型字符串
     */
    public static String getYearMothDays(String str) {
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat time_mm = new SimpleDateFormat("yyyy/MM/dd");
        String result = "";
        try {
            Date parse = time_mm.parse(str);
            result = time.format(parse);
        } catch (ParseException e) {
            return "";
        }

        return result;
    }

    //年月日
    public static String getYearMothDay(long timeLong, String dateFormat) {
        SimpleDateFormat time = new SimpleDateFormat(dateFormat);
        return time.format(new Date(timeLong));
    }

    //年月日 时分
    public static String getYearMothDay2(long timeLong, String dateFormat) {
        SimpleDateFormat time_mm = new SimpleDateFormat(dateFormat + " HH:mm");
        return time_mm.format(new Date(timeLong));
    }

    //年月日 时分秒
    public static String getYearMothDay3(long timeLong, String dateFormat) {
        SimpleDateFormat time_mm = new SimpleDateFormat(dateFormat + " HH:mm:ss");
        return time_mm.format(new Date(timeLong));
    }

    /**
     * @param
     * @return 返回 HH:mm类型字符串
     */
    public static String getHHmm(String str) {
        SimpleDateFormat time = new SimpleDateFormat("HH:mm");
        SimpleDateFormat time_mm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String result = "";
        try {
            Date parse = time_mm.parse(str);
            result = time.format(parse);
        } catch (ParseException e) {
            return str;
        }

        return result;
    }

    /**
     * @param
     * @return 返回 HH:mm类型字符串
     */
    public static String getMMddHHmm(String str) {
        SimpleDateFormat time = new SimpleDateFormat("HH:mm");
        SimpleDateFormat time_mm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String result = "";
        try {
            Date parse = time_mm.parse(str);
            result = time.format(parse);
        } catch (ParseException e) {
            return str;
        }

        return result;
    }

    /**
     * @param
     * @return 返回 MM-dd类型字符串
     */
    public static String getMMdd(String str) {
        SimpleDateFormat time = new SimpleDateFormat("MM-dd");
        SimpleDateFormat time_mm = new SimpleDateFormat("yyyy-MM-dd");
        String result = "";
        try {
            Date parse = time_mm.parse(str);
            result = time.format(parse);
        } catch (ParseException e) {
            return str;
        }

        return result;
    }

    /**
     * @param longTime 毫秒值
     * @return 返回 HH:mm类型字符串
     */
    public static String getMonthHourMinuteTime(long longTime) {
        SimpleDateFormat time = new SimpleDateFormat("MM-dd HH:mm");
        String result = time.format(new Date(longTime));
        return result;
    }

    /**
     * @param longTime 毫秒值
     * @return 返回 HH:mm类型字符串
     */
    public static String getMonthHourMinuteChinese(long longTime) {
        SimpleDateFormat time = new SimpleDateFormat("HH:mm");
        String result = time.format(new Date(longTime));
        return result;
    }

    /**
     * @param longTime 毫秒值
     * @return 返回 HH:mm类型字符串
     */
    public static String getMonthHourMinuteTimeChinese(long longTime) {
        SimpleDateFormat time = new SimpleDateFormat("MM月dd日 HH:mm");
        String result = time.format(new Date(longTime));
        return result;
    }
    /**
     * @param longTime 毫秒值
     * @return 返回 HH:mm类型字符串
     */
    public static String getYearMonthHourMinuteTimeChinese(long longTime) {
        SimpleDateFormat time = new SimpleDateFormat("yyyy年MM月dd日");
        String result = time.format(new Date(longTime));
        return result;
    }
    /**
     * long 类型字符串 转换成事件 yyyy-MM-dd HH:mm
     *
     * @param longString
     * @return
     */
    public static String longStringToStringChinese(String longString) {
        try {
            Long aLong = Long.valueOf(longString);
            Date date = new Date(aLong);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            return format.format(date);
        } catch (Exception e) {
            return "";
        }
    }

    public static String getYyyyMmDd(long longTime) {
        Date date = new Date(longTime);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return format.format(date);
    }

    public static String longStringToTwoDaysDistance(String longString) {
        Long aLong = Long.valueOf(longString);
        Date date = new Date(aLong);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return getTwoDaysDistance(format.format(date));
    }

    public static String generateTime(long position) {
        int totalSeconds = (int) (position / 1000);

        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds / 60) % 60;
        int hours = totalSeconds / 3600;

        if (hours > 0) {
            return String.format(Locale.CHINA, "%02d:%02d:%02d", hours, minutes,
                    seconds).toString();
        } else {
            return String.format(Locale.CHINA, "%02d:%02d", minutes, seconds)
                    .toString();
        }
    }

    public static String generateHMTime(long position) {
        int totalSeconds = (int) (position / 1000);
        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds / 60) % 60;
        int hours = totalSeconds / 3600;
        return String.format(Locale.CHINA, "%02d:%02d:%02d", hours, minutes, seconds).toString();
    }

    /**
     * 将文件进行base64编码,
     *
     * @param fileStr
     * @return
     */
    public static String encodeBase64(String fileStr) {
        File file = new File(fileStr);
        String result = null;
        if (file.exists()) {
            try {
                FileInputStream inputStream = new FileInputStream(file);
                int len = -1;
                byte[] data = new byte[1024];
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                while ((len = inputStream.read(data)) != -1) {
                    os.write(data, 0, len);
                }
                byte[] resData = os.toByteArray();
                byte[] encode = Base64.encode(resData, Base64.DEFAULT);
                inputStream.close();
                result = new String(encode);
                //进行URL编码
                result = URLEncoder.encode(result, "UTF-8");

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }

    /**
     * 将bitmap转换成base64字符串
     *
     * @param bitmap
     * @return base64 字符串
     */
    public static String encodeBase64(Bitmap bitmap) {
        String result = null;
        ByteArrayOutputStream bos = null;
        try {
            if (null != bitmap) {
                bos = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 90, bos);//将bitmap放入字节数组流中
                bos.flush();//将bos流缓存在内存中的数据全部输出，清空缓存
                bos.close();
                byte[] bitmapByte = bos.toByteArray();
                result = Base64.encodeToString(bitmapByte, Base64.DEFAULT);
                //进行URL编码
                result = URLEncoder.encode(result, "UTF-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != null) {
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }


    /**
     * @param dot 输入0.0或者0.00标识保留几位
     * @return
     */
    public static String getDouble(String dot, Double dotNumber) {
        DecimalFormat df = new DecimalFormat(dot);
        String number = df.format(dotNumber);
        return number;
    }


    /**
     * 获取手机型号
     *
     * @return
     */
    public static String getMobileType() {
        return Build.MODEL;
    }

    /**
     * 获取手机厂商
     *
     * @return 手机厂商
     */
    public static String getDeviceBrand() {
        return Build.BRAND;
    }

    /**
     * 获取设备系统版本
     *
     * @return
     */
    public static String getEquipSysVersion() {
        return Build.VERSION.RELEASE;
    }

    /**
     * 获取设备应用版本
     *
     * @return
     */
    public static String getAppVersion(Context context) {
        String versionCode = "";
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            versionCode = String.valueOf(packInfo.versionCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    /**
     * 返回当前程序版本名
     */
    public static String getAppVersionName(Context context) {
        String versionName = "";
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {

        }
        return versionName;
    }


    /**
     * 将得到的int类型的IP转换为String类型
     *
     * @param ip
     * @return
     */
    public static String intIP2StringIP(int ip) {
        return (ip & 0xFF) + "." +
                ((ip >> 8) & 0xFF) + "." +
                ((ip >> 16) & 0xFF) + "." +
                (ip >> 24 & 0xFF);
    }


    //    String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";//特殊字符
    //emoji表情匹配的unicode码  会常更新
    static String emoij_rule2 = "(?:[\uD83C\uDF00-\uD83D\uDDFF]|[\uD83E\uDD00-\uD83E\uDDFF]|[\uD83D\uDE00-\uD83D\uDE4F]|[\uD83D" +
            "\uDE80-\uD83D\uDEFF]|[\u2600-\u26FF]\uFE0F?|[\u2700-\u27BF]\uFE0F?|\u24C2\uFE0F?|[\uD83C\uDDE6-\uD83C\uDDFF]{1," +
            "2}|[\uD83C\uDD70\uD83C\uDD71\uD83C\uDD7E\uD83C\uDD7F\uD83C\uDD8E\uD83C\uDD91-\uD83C\uDD9A]\uFE0F?|[\u0023\u002A" +
            "\u0030-\u0039]\uFE0F?\u20E3|[\u2194-\u2199\u21A9-\u21AA]\uFE0F?|[\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55]\uFE0F" +
            "?|[\u2934\u2935]\uFE0F?|[\u3030\u303D]\uFE0F?|[\u3297\u3299]\uFE0F?|[\uD83C\uDE01\uD83C\uDE02\uD83C\uDE1A\uD83C" +
            "\uDE2F\uD83C\uDE32-\uD83C\uDE3A\uD83C\uDE50\uD83C\uDE51]\uFE0F?|[\u203C\u2049]\uFE0F?|[\u25AA\u25AB\u25B6\u25C0" +
            "\u25FB-\u25FE]\uFE0F?|[\u00A9\u00AE]\uFE0F?|[\u2122\u2139]\uFE0F?|\uD83C\uDC04\uFE0F?|\uD83C\uDCCF\uFE0F?|[\u231A" +
            "\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA]\uFE0F?)";
//    static String emoij_rule2 = "[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]";

    /**
     * 过滤emoji表情
     *
     * @param source
     * @return
     */
    public static String filterEmoji(String source) {
        if (source != null) {
            Pattern emoji = Pattern.compile(emoij_rule2, Pattern
                    .UNICODE_CASE | Pattern.CASE_INSENSITIVE);
            Matcher emojiMatcher = emoji.matcher(source);
            if (emojiMatcher.find()) {
                source = emojiMatcher.replaceAll("");
                return source;
            }
            return source;
        }
        return source;
    }


    /**
     * 判断是含有emoji表情
     *
     * @param source
     * @return
     */
    public static Boolean hasEmoji(String source) {
        if (source != null) {
            Pattern emoji = Pattern.compile(emoij_rule2, Pattern
                    .UNICODE_CASE | Pattern.CASE_INSENSITIVE);
            Matcher emojiMatcher = emoji.matcher(source);
            if (emojiMatcher.find()) {
                return true;
            }
            return false;
        }
        return false;
    }

    public static String initNum2TwoByte(int num) {
        if (num <= 0) {
            return num + "";
        } else if (num < 10) {
            return "0" + num;
        } else {
            return num + "";
        }
    }

    public static String intNumToString(String intNum) {
        switch (intNum) {
            case "1":
                return "一";
            case "2":
                return "二";
            case "3":
                return "三";
            case "4":
                return "四";
            case "5":
                return "五";
            case "6":
                return "六";
            case "7":
                return "七";
            case "8":
                return "八";
            case "9":
                return "九";
            case "0":
                return "零";
        }
        return "";
    }

    public static String getTodayStringWeek() {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int i = calendar.get(Calendar.DAY_OF_WEEK);
        if (i - 1 == 0) {
            return "星期日";
        } else {
            return "星期" + intNumToString(i - 1);
        }
    }

    public static String getDateStringWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int i = calendar.get(Calendar.DAY_OF_WEEK);
        if (i - 1 == 0) {
            return "星期日";
        } else {
            return "星期" + intNumToString(i - 1);
        }
    }

    public static String intNumToString(int intNum) {
        switch (intNum) {
            case 1:
                return "一";
            case 2:
                return "二";
            case 3:
                return "三";
            case 4:
                return "四";
            case 5:
                return "五";
            case 6:
                return "六";
            case 7:
                return "七";
            case 8:
                return "八";
            case 9:
                return "九";
            case 0:
                return "零";
        }
        return "";
    }


    public static CharSequence getUpperText(String content, String upText) {
        String result = content + upText;
        SpannableStringBuilder builder = new SpannableStringBuilder(result);
        builder.setSpan(new SuperscriptSpan(), content.length(), result.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        builder.setSpan(new RelativeSizeSpan(0.6f), content.length(), result.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        return builder;
    }

    public static CharSequence getUpperText(String scoreA, String scoreB, String upText) {
        String result = scoreA + upText + ":" + scoreB;
        SpannableStringBuilder builder = new SpannableStringBuilder(result);
        builder.setSpan(new SuperscriptSpan(), scoreA.length(), scoreA.length() + upText.length(),
                Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        builder.setSpan(new RelativeSizeSpan(0.6f), scoreA.length(), scoreA.length() + upText.length(),
                Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        return builder;
    }


}
